<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: 12460
  Date: 2024/11/30
  Time: 16:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>遍历数组和map</title>
</head>
<body>
    <%
        //准备数组
        int [] nums={100,200,300,400,500,600};
        request.setAttribute("nums",nums);
        //准备map
        HashMap<String, String> maps = new HashMap<>();
        //存入值  键-值的形式
        maps.put("city1","重庆");
        maps.put("city2","陕西");
        maps.put("city3","湖南");
        maps.put("city4","北京");
        //放入请求域
        request.setAttribute("maps",maps);

    %>

    <h2>遍历数组</h2>
    <c:forEach items="${nums}" var="n">
        ${n} &nbsp;
    </c:forEach>

    <h2>遍历map</h2>
    <%-- key和value--%>
    <c:forEach items="${maps}" var="entry">
        ${entry.key}=======> ${entry.value} <br>
    </c:forEach>
</body>
</html>
